/**
 * zmn 免责条款编辑
 * @author linfeng
 * @since 2020-09-24 14:35:13
 */
layui.define(['index', 'form', 'table', 'laypage', 'layedit', 'laydate'], function (exports) {
    var $ = layui.$;
    var form = layui.form;
    var layer = layui.layer;
    var laydate = layui.laydate;

    form.render(null, "zmn-form");

    laydate.render({elem: "#perTime", type: "date"});

    // 提交
    form.on('submit(zmn-form-submit)', function(obj){
        var data = obj.field;

        if (data.disclaimer.length > 500) {
            layer.alert("免责条款不能超过500字");
            return;
        }

        var url = "/serv/categ/ass/updateDisclaimer.action";

        $.ajax({
            async: false,
            type: "POST", url: url,
            dataType: "json", data: {"id": data.groupId, "disclaimer": data.disclaimer},
            success:function(result) {
                if(result.status == 200) {
                    parent.reload(result.message);
                    cancel();
                } else {
                    layui.layer.msg(result.message,{"icon":2});
                }
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
            }
        });

        return false;
    });

    //对外暴露的接口
    exports('plat_servAssCategory_disclaimer', {});
});

// 取消
function cancel() {
    let index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
    parent.layer.close(index);
}